package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tech.aistar.entity.Show;
import tech.aistar.service.ShowService;

import java.util.List;

/**
 * 本类用来演示:
 *
 * @author jyz
 * @date 2023/3/4 16:23:50
 */

@RestController
@RequestMapping( "/show")
public class ShowController {

    @Autowired
    private ShowService showService;

    //通过id得到信息
    @RequestMapping(value = "/getShow/{id}")
    public String getShow(@PathVariable int id){
        return showService.getShow(id).toString();
    }

    //通过id删除信息
    @RequestMapping(value = "/delete")
    public String delete(int id){
        int result = showService.delete(id);
        if(result >= 1){
            return "删除成功！";
        }else{
            return "删除失败！";
        }
    }

    //更改信息
    @RequestMapping(value = "/update")
    public String update(Show show){
        int result = showService.update(show);
        if(result >= 1){
            return "更新成功！";
        }else{
            return "更新失败！";
        }
    }

    //插入信息
    @RequestMapping(value = "/insert")
    public int insert(Show show){
        return showService.save(show);
    }

    //查询所有的信息
    @RequestMapping(value = "/findAll")
    @ResponseBody   //理解为：单独作为响应体，这里不调用实体类的toString方法
    public List<Show> listShow(){
        return showService.findAll();
    }
}
